package org.example.Util;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jws;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;

@Component
public class JwtUtil {
    @Value("${jwt.sercret}")
    private String sercret;
    private Date DATE = new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24 * 7);

    public String createToken(Map<String, Object> claims) {
        String jwt =Jwts.builder()
                .signWith(SignatureAlgorithm.HS256,sercret)
                .setClaims(claims)
                .setExpiration(DATE)
                .compact();
        return jwt;
    }

    public Claims checkToken(String token) {
        Claims claimsJws = Jwts.parser()
                .setSigningKey(sercret)
                .parseClaimsJws(token)
                .getBody();
        return claimsJws;
    }
}

